home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / proctypa.zip / PROCCA.ASM
Assembly Source File  |  1990-07-21  |  9KB  |  146 lines

  1. ;**********************************************************************;
  2. ;*                           P R O C C A                              *;
  3. ;*--------------------------------------------------------------------*;
  4. ;*    Task           : Make a function available to a C program which *;
  5. ;*                     examines the type of processor installed in a  *;
  6. ;*                     PC and informs the calling program of this     *;
  7. ;*                     information.                                   *;
  8. ;*--------------------------------------------------------------------*;
  9. ;*    Author         : MICHAEL TISCHER                                *;
  10. ;*    Developed on   : 08/15/1988                                     *;
  11. ;*    Last update    : 05/24/1989                                     *;
  12. ;*--------------------------------------------------------------------*;
  13. ;*    assembly       : MASM PROCCA;                                   *;
  14. ;*                     ... link to a C program                        *;
  15. ;**********************************************************************;
  16.                                                                         
  17. IGROUP group _text                ;Include program segment
  18. DGROUP group const,_bss,  _data   ;Include data segment
  19.        assume CS:IGROUP, DS:DGROUP, ES:DGROUP, SS:DGROUP
  20.                                                                         
  21. CONST  segment word public 'CONST';This segment includes all read-only
  22. CONST  ends                       ;constants 
  23.                                                                         
  24. _BSS   segment word public 'BSS'  ;This segment includes al un-initial-
  25. _BSS   ends                       ;ized static variables 
  26.                                                                         
  27. _DATA  segment word public 'DATA' ;This segment includes all initialized
  28.                                   ;gobal and static variables
  29.                                                                         
  30. _DATA  ends
  31.                                                                         
  32. ;== Constants ==========================================================
  33.                                                                         
  34. p_80386   equ   7                 ;Codes for different processor tpyes
  35. p_80286   equ   6
  36. p_80186   equ   5
  37. p_80188   equ   4
  38. p_v30     equ   3
  39. p_v20     equ   2
  40. p_8086    equ   1
  41. p_8088    equ   0
  42.                                                                         
  43. ;== Program ============================================================
  44.                                                                         
  45. _TEXT  segment byte public 'CODE' ;Program segment
  46.                                                                         
  47. public   _getproc                 ;Function made available for other
  48.                                   ;programs
  49.                                                                         
  50. ;-- GETPROC: Determines the type of processor in the current PC --------
  51. ;-- Call from C : int getproc( void );
  52. ;-- Output      : The processor type's number (see constants above)
  53.                                                                         
  54. _getproc  proc near
  55.                                                                         
  56.           pushf                   ;Secure flag register contents
  57.                                                                         
  58.           ;-- Test for 80386/80286 -------------------------------------
  59.                                                                         
  60.           xor  ax,ax              ;Set AX to 0
  61.           push ax                 ;and push onto stack
  62.           popf                    ;Pop flag register off of stack
  63.           pushf                   ;Push back onto stack
  64.           pop  ax                 ;and pop off of AX
  65.           and  ax,0f000h          ;Do not clear the upper 4 bits
  66.           cmp  ax,0f000h          ;Are bits 12-15 al equal to 1?
  67.           je   not_a_386          ;YES --> Not an 80386 or 80286
  68.                                                                         
  69.           ;-- Test for handling as an 80386 or 80286 -------------------
  70.                                                                         
  71.           mov  dl,p_80286         ;In any case, this routine checks for
  72.           mov  ax,07000h          ;one of the two processors
  73.           push ax                 ;Push 07000h onto stack 
  74.           popf                    ;Pop flag register off
  75.           pushf                   ;and push back onto the stack
  76.           pop  ax                 ;Pop into AX register
  77.           and  ax,07000h          ;Bits 12-14 not included
  78.           je   pende              ;Are bits 12-14 all equal to 0?
  79.                                   ;YES--> Handle it as an 80286
  80.                                                                         
  81.           inc  dl                 ;NO --> Handle it as an 80386
  82.           jmp  pende              ;End test
  83.                                                                         
  84.           ;-- Test for 80186 or 80188 ----------------------------------
  85.                                                                         
  86. not_a_386 label near
  87.                                                                         
  88.           mov  dl,p_80188         ;Load code for 80188
  89.           mov  al,0ffh            ;Set all bits in AL register to 1
  90.           mov  cl,021h            ;Move number of shift operations to CL
  91.           shr  al,cl              ;AL CL shift to the right
  92.           jne  t88_86             ;If AL <> 0, handle is as an
  93.                                   ;80188 or 80186
  94.                                                                         
  95.           ;-- Test for NEC V20 or V30 ----------------------------------
  96.                                                                         
  97.           mov  dl,p_v20           ;Load code for NEC V20
  98.           sti                     ;Enable interrupts
  99.           push si                 ;Mark contents of SI register
  100.           mov  si,0               ;Starting with first byte in ES, read 
  101.           mov  cx,0ffffh          ;a complete segment
  102.           rep  lods byte ptr es:[si]  ;REP with a segment override
  103.                                       ;(works ony with NEC V20, V30)
  104.           pop  si                 ;Pop SI off of stack
  105.           or   cx,cx              ;Has entire segment been read?
  106.           je   t88_86             ;YES--> V20 or V30
  107.                                                                         
  108.           mov  dl,p_8088          ;NO --> Must be 8088 or 8086
  109.                                                                         
  110.           ;-- Test for 88/86 or V20/V30 --------------------------------
  111.                                                                         
  112. t88_86    label near
  113.                                                                         
  114.           push cs                 ;Push CS onto stack
  115.           pop  es                 ;and pop ES off 
  116.           std                     ;Increment on string instructions 
  117.           mov  di,offset q_end    ;
  118.           mov  al,0fbh            ;Instruction code for "STI"
  119.           mov  cx,3               ;Execute string instruction 3 times 
  120.           cli                     ;Suppress interrupts
  121.           rep  stosb
  122.           cld                     ;Increment on string instructions
  123.           nop                     ;Fill queue with dummy instructions
  124.           nop
  125.           nop
  126.                                                                         
  127.           inc  dx                 ;Increment processor code
  128.           nop
  129. q_end:    sti                     ;Re-enable interrupts
  130.                                                                         
  131.           ;-------------------------------------------------------------
  132.                                                                         
  133. pende     label near              ;End testing
  134.                                                                         
  135.           popf                    ;Pop flag register off of stack
  136.           xor  dh,dh              ;Set high byte of proc. code to 0
  137.           mov  ax,dx              ;Processor code=return value of funct.
  138.           ret                     ;Back to caller
  139.                                                                         
  140. _getproc  endp                    ;End of procedure
  141.                                                                         
  142. ;== End ================================================================
  143.                                                                         
  144. _text    ends                     ;End of program segment
  145.          end                      ;End of assembler source
  146.